﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="page-container">
    <div class="page-content">

        <div class="titlePanel">
            <div class="title-search">
                <table>
                    <tr>
                        <td>任务状态</td>
                        <td style="padding-left: 10px;">
                            <div id="txt_condition" class="btn-group ">
                                <a class="btn btn-default dropdown-text" data-toggle="dropdown" data-value="" aria-expanded="false">请选择</a>
                                <a class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="true"><span class="caret"></span></a>

                                <ul class="dropdown-menu " role="menu">
                                    <li><a data-value="DbName">数据库名</a></li>
                                    <li><a data-value="FileName">备份名称</a></li>
                                </ul>
                            </div>

                        </td>
                        <td style="padding-left: 2px;">
                            <input id="txt_keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                        </td>
                        <td style="padding-left: 5px;">
                            <a id="btn_search" class="btn btn-primary btn-sm"><i class="fa fa-search"></i>&nbsp;查询</a>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="toolbar">
                <div class="btn-group">
                    <a id="replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                    <a id="add" authorize="yes" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增备份</a>
                    <a id="delete" authorize="yes" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-pencil-square-o"></i>&nbsp;删除备份</a>
                    <a id="download" authorize="yes" class="btn btn-default" onclick="btn_download()"><i class="fa fa-trash-o"></i>&nbsp;下载备份</a>
                </div>
                <script>$('.toolbar').authorizeButton();</script>
            </div>
        </div>
        <div class="gridPanel">
            <table id="gridTable"></table>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        gridTable();
    })
    function gridTable() {
        var $gridTable = $("#gridTable");
        $gridTable.jqGridEx({
            url: "/SystemSecurity/DbBackup/GetGridJson",
            height: $(window).height() - 96,
            colModel: [
                { label: "主键", name: "Id", hidden: true, key: true },
                { label: '数据库名', name: 'DbName', width: 100 },
                { label: '备份名称', name: 'FileName', width: 200 },
                { label: '大小', name: 'FileSize', width: 100 },
                {
                    label: '备份模式', name: 'BackupType', width: 100,
                    formatter: function (cellvalue) {
                        if (cellvalue == "1") {
                            return "完整备份";
                        } else if (cellvalue == "2") {
                            return "差异备份";
                        }
                    }
                },
                {
                    label: '备份时间', name: 'CreatorTime', width: 120,
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i', newformat: 'Y-m-d H:i' }
                },
                { label: '备份人员', name: 'CreatorUserId', width: 100 },
                { label: '备份说明', name: 'Description', width: 300, align: 'left' }
            ]
        });
        $("#txt_condition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#txt_condition .dropdown-text").html(text).attr('data-value', value)
        });
        $("#btn_search").click(function () {
            var queryJson = {
                condition: $("#txt_condition").find('.dropdown-text').attr('data-value'),
                keyword: $("#txt_keyword").val()
            }
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) },
            }).trigger('reloadGrid');
        });
    }
    function btn_add() {
        $.fn.modalOpen({
            id: "Form",
            title: "新增备份",
            url: "/SystemSecurity/DbBackup/Form",
            width: "450px",
            height: "360px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.fn.deleteForm({
                url: "/SystemSecurity/DbBackup/DeleteForm",
                param: { keyValue: keyValue },
                success: function () {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        }
    }
    function btn_download() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.download("/SystemSecurity/DbBackup/DownloadBackup", "keyValue=" + keyValue, 'post');
        }
    }
</script>
